﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestConsoleApp
{
    public class TestGenericClasses
    {

        public static void Test()
        {

            MyMainViewModel myMainViewModel = new MyMainViewModel();
            myMainViewModel.show();

            Console.ReadLine();
        }

    }


    public class MyMainViewModel : baseMainViewModel<MyInfo, MyViewModel>
    {
        public MyMainViewModel()
        {
            list.Add(new MyViewModel());
            list.Add(new MyViewModel(new MyInfo() { a = 1, b = 1 }));
        }

     
    }


    public class baseMainViewModel<T, U>
        where T : baseInfo
        where U : baseViewModel<T>
    {

        public List<U> list;

        public baseMainViewModel()
        {
            list = new List<U>();
        }


        public virtual void show()
        {
            list.ForEach(par =>
            {
                par.show();
            });

        }
    }

    public class MyViewModel : baseViewModel<MyInfo>
    {

        public MyViewModel()
            : base(new MyInfo())
        {

        }

        public MyViewModel(MyInfo myInfo)
            : base(myInfo)
        {

        }

        public override void show()
        {
            Console.WriteLine($"{data.a + "----" + data.b}");
        }

    }




    public class baseViewModel<T> where T : baseInfo
    {
        public T data;


        public baseViewModel(T mydata)
        {
            data = mydata;
        }

        public virtual void show()
        {
            Console.WriteLine($"{data.a} ");
        }
    }


    public class MyInfo : baseInfo
    {

        public int b;
    }


    public class baseInfo
    {

        public int a;
    }
}
